package de.homelabs.bookstore.web.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import de.homelabs.bookstore.domain.Category;
import de.homelabs.bookstore.domain.News;
import de.homelabs.bookstore.web.ui.MenuEntry;

@Controller
public class ErrorController {

	@RequestMapping("/error.htm")
	public ModelAndView errorHandler(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		Map<String, Object> modelData = new HashMap<String, Object>();
		
		List<News> newsList = new ArrayList<News>();
		newsList.add(new News("May 25, 2011", "Dirk M&uuml;ller", "<p>Es ist ein Fehler aufgetreten!</p>"));
		modelData.put("newslist", newsList);
		
		List<Category> categoriesList = new ArrayList<Category>();
		categoriesList.add(new Category("erste Kategorie"));
		modelData.put("categoryList", categoriesList);
		
		//mainMenu
		List<MenuEntry> menu = new ArrayList<MenuEntry>();
		menu.add(new MenuEntry("Home","index.htm"));
		menu.add(new MenuEntry("News",""));
		menu.add(new MenuEntry("Impressum",""));
		menu.add(new MenuEntry("About",""));
		
		modelData.put("menuEntries", menu);
		//return 
		//return new ModelAndView("index", templateService.createView("default", modelData));
		
		modelData.put("content", "<p>Es ist ein Fehler aufgetreten!</p>");
		//FreeMarkerCascadedView
		return new ModelAndView("test.ftl", modelData);
		
		//HLFreeMarkerViewWithTemplateManager
		//return new ModelAndView("default", modelData);
	}
}
